#!/usr/bin/env python3

import os

def main():
    fd = os.pipe()
    print(fd[0], fd[1])

    if os.fork() == 0:
        print("child pid = %d, ppid = %d" % (os.getpid(), os.getppid()))
        os.close(fd[0])
        while True:
            s = input("\033[3;1H\033[2Ksend: ")
            os.write(fd[1], s.encode())
            if s == 'exit':
                break
        os._exit(0)

    os.close(fd[1])
    while True:
        s = os.read(fd[0], 1024)
        if s.decode() == "exit":
            break
        print("\033[s\033[1;1H\033[2Krecv: %s\033[u" % s.decode(), end='', flush=True)

if __name__ == "__main__":
    main()
